package com.jinglu.cloud.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.net.URLDecoder;
import java.net.URLEncoder;

public class EncodeUtils {

    /**
     * utf-8编码
     * @param content
     * @return
     */
    public static String encodeUtf8(String content) {
        if (StringUtils.isBlank(content)) return "";
        try {
            return URLEncoder.encode(content, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * UTF-8解码
     * @param content
     * @return
     */
    public static String decodeUtf8(String content) {
        if (StringUtils.isBlank(content)) return "";
        try {
            return URLDecoder.decode(content, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
